# 使用 Ubuntu 18.04 作为基础镜像
FROM ubuntu:18.04

# 添加自定义源
RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ trusty main universe" >> /etc/apt/sources.list

# 设置非交互式前端
ENV DEBIAN_FRONTEND=noninteractive

# 更新系统、安装依赖、清理缓存
RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y software-properties-common && \
    add-apt-repository ppa:openjdk-r/ppa && \
    apt-get update && \
    apt-get install -y \
        locales \
        build-essential \
        git \
        gperf \
        curl \
        wget \
        sudo \
        python3 \
        python3-pip \
        bc \
        cpio \
        rsync \
        unzip \
        zip \
        libssl-dev \
        liblz4-tool \
        libncurses5-dev \
        libxml2-utils \
        xsltproc \
        zlib1g-dev \
        gcc-multilib \
        g++-multilib \
        libc6-dev-i386 \
        lib32ncurses5-dev \
        lib32z1-dev \
        uuid-dev \
        chrpath \
        diffstat \
        binfmt-support \
        qemu-user-static \
        live-build \
        bison \
        flex \
        fakeroot \
        cmake \
        device-tree-compiler \
        zstd \
        openjdk-8-jdk \
        clang \
        libyaml-dev \
        expect \
        mingw32 \
        cgpt \
        texinfo \
        patchelf \
        gawk \
        bsdmainutils \
        repo \
        ssh \
        make \
        python-pip \
        libgmp-dev \
        libmpc-dev \
        patch \
        bzip2 \
        gettext \
        pkg-config \
        subversion \
        python-yaml \
        ocaml-nox \
        ocaml \
        libfdt-dev \
        coccinelle \
        ocaml-findlib \
        libpycaml-ocaml-dev \
        libmenhir-ocaml-dev \
        net-tools \
        desktop-file-utils \
        docbook-utils \
        help2man \
        libmpfr-dev \
        libreadline6-dev \
        libtool \
        python-pysqlite2 \
        quilt \
        sed \
        texi2html \
        vim \
        tree \
        dos2unix \
        ccache \
        lynx \
        xterm \
        tmux \
        mc \
        re2c \
        u-boot-tools \
        liblzo2-dev \
        squashfs-tools \
        openssh-server \
        libgl1-mesa-dev \
        tofrodos \
        python-markdown \
        dpkg-dev \
        libsdl1.2-dev \
        gnupg \
        x11proto-core-dev \
        libx11-dev \
        m4 \
	time \
	python3-docutils  \
        libtinfo5 \
        libxml-simple-perl \
        liblz4-dev \
        tzdata \
	iputils-ping libcap2-bin libpam-cap python3-pexpect python3-ptyprocess socat  \
        && rm -rf /var/lib/apt/lists/*

# 配置 Python 和 Perl
RUN update-alternatives --install /usr/bin/python python /usr/bin/python2 27001 && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3 3600 && \
    usr/bin/pip install pyhocon enum34 pycryptodome

#    python3 -m pip install --upgrade pip 

# 配置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone

# 配置语言环境
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# 创建用户
ARG user=test
RUN useradd --create-home --no-log-init --shell /bin/bash ${user} \
    && adduser ${user} sudo \
    && echo "${user}:1" | chpasswd

# 创建 /SDK/ 目录并设置所有者为 ${user}
RUN mkdir -p /SDK && chown -R ${user}:${user} /SDK

# 克隆 LZ4 仓库并安装
RUN git clone https://github.com/lz4/lz4.git --depth 1 -b v1.9.4 && \
    cd lz4 && \
    make install -j8 && \
    cd .. && \
    rm -rf lz4

# 安装 Git LFS
RUN apt-get update && \
    apt-get install -y software-properties-common && \
    curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \
    apt-get update && \
    apt-get install -y git-lfs && \
    git lfs install && \
    rm -rf /var/lib/apt/lists/*

# 配置 SSH
EXPOSE 22
RUN sed -i '/^AcceptEnv LANG LC_\*/c\AcceptEnv no' /etc/ssh/sshd_config

# 切换到普通用户
WORKDIR /home/${user}
USER ${user}

